#!/usr/bin/python

import sys
import re

tabfile = sys.argv[1]
modulefile = sys.argv[2]

tf = open(tabfile, "rU")
tfl = tf.readlines()

mf = open(modulefile, "rU")
mfl = mf.readlines()

ko = re.compile('KO:\t(.*)\t(.*)')
ko_and = re.compile('.*\+.*')
ko_or = re.compile(',')
cog = re.compile('COG:\t(.*)\t(.*)')

for line in mfl:
    l = line.rstrip()
    if ko.match(l):
        p = ko.match(l)
        kos = p.group(1)
        kslices = kos.split(',')
        #print p.group(1)
        #print len(kslices)
        if ko_and.search(kos): #at least one '+'
            print kos
        elif ko_or.search(kos): #at least one ','
            print kos
        else: #only singles
            print kos
tf.close()
mf.close()